package com.chenjt.juc.seven_volatile;

import java.util.concurrent.TimeUnit;

/**
 * 注释：
 *
 * @author chenjt
 * @date 2024/7/10 10:33
 */


class MyNumber{

//    int number;
    volatile int number;

    public synchronized void addPlusPlus(){
        number++;
    }


}

public class VolatileNoAtomicDemo {

    public static void main(String[] args) {
        MyNumber myNumber = new MyNumber();

        for(int i = 1;i<=10;i++){
            new Thread(()->{
                for(int j = 1;j<=1000;j++){
                    myNumber.addPlusPlus();
                }
            },String.valueOf(i)).start();
        }

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println(myNumber.number);


    }

}
